
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <link href="/static/devtools30/layui-v2.5.6/ext/soulTable/soulTable.css" rel="stylesheet"/>

    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <title>表维护</title>
    <style>
        body {
            background: #F7F7F7;
        }


        /*顶部容器*/

        .tophead {
            height: 32px;
            line-height: 32px;
            border: 1px solid #F7F7F7;
            padding: 0 5px;
            margin: 0 2px;
        }

        .tophead .layui-form-item {
            margin-bottom: 0px!important;
        }

        .tophead .layui-form-label {
            padding: 1px;
            line-height: 25px;
            width: auto;
        }

        .tophead .layui-input-block {
            margin-left: 32px;
        }

        .tophead .layui-input,
        .layui-select {
            height: 25px;
        }

        .tophead .layui-form-select dl {
            top: 26px;
            padding: 0;
        }

        .tophead .layui-form-select dl dd,
        .layui-form-select dl dt {
            line-height: 24px;
        }

        .tophead .layui-form-item {
            width: 165px;
        }

        .tophead .layui-form-select .layui-edge {
            border-width: 4px;
        }

        .tophead .search .layui-input-block {
            margin-left: 32px;
        }

        .tophead .layui-input-block {
            min-height: 26px;
        }


        /*按钮组边框*/

        .layui-btn-group .layui-btn-primary:first-child {
            border-left: 1px solid #c9c9c9!important;
        }

        .layui-btn-group .layui-btn {
            border-left: 1px solid rgba(255, 255, 255, .5)!important;
        }


        /*按钮大小*/

        .layui-btn {
            height: 26px;
            line-height: 26px;
            font-size: 11px;
        }


        /*table*/

        .layui-table,
        .layui-table-view {
            margin: 0;
        }

        .layui-table td,
        .layui-table th {
            font-size: 11px!important;
        }
    </style>
</head>
<body>
<div>
    <div class="flex flex-align-center flex-jusity-betreen tophead backgroundf">
        <div class="flex flex-align-center">
            <div class="layui-form flex flex-align-center" lay-filter="searchform">
                <div class="layui-form-item">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <select id="selType" lay-filter="selType">

                        </select>
                    </div>
                </div>

                <div class="layui-form-item marginleft10 search">
                    <label class="layui-form-label">查询</label>
                    <div class="layui-input-block">
                        <input type="text" id="searchValue" name="searchValue" placeholder="请输入表代码/表名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button type="button" class="layui-btn layui-btn-sm layui-btn-normal marginleft10" onclick="loadData()">确定</button>
            </div>
        </div>
        <div class="layui-btn-group btnwrap">
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" name='add'>保存</button>
        </div>
    </div>
    <div style="padding: 2px;width: 100%;background: #F7F7F7;">
        <div class="backgroundf">
            <table id="mygrid" lay-filter="mygrid"></table>
        </div>
    </div>
</div>
</body>
<script>



    var height = dlCommon.getWinHeight();
    var width=dlCommon.getWinWidth();
    var selTableId="";
    var planid='[(${planid})]'

    layui.config({
        base: '/static/devtools30/layui-v2.5.6/ext/',// 第三方模块所在目录
        version: 'v1.5.10' // 插件版本号
    }).extend({
        soulTable: 'soulTable/soulTable',
        tableChild: 'soulTable/tableChild',
        tableMerge: 'soulTable/tableMerge',
        tableFilter: 'soulTable/tableFilter',
        excel: 'soulTable/excel',
        dltable: 'treegrid/dltable',
        treeGrid:'treegrid/treeGrid'
    });

    layui.use(['form', 'table', 'jquery','treeGrid','layer','soulTable','tree'], function(){
        $(function() {

            initGrid();

            initEvent();

            bindForm();

            loadData();

        })
    });
    //数据表
    function loadData(){
        // layui.form.val('searchform');
        // alert(layui.form.val('searchform'))

        var data={
            serach:$("#searchValue").val(),
            typeid:$("#selType").val(),
            planId:planid
        };
        layui.table.reload("mygrid",{
            url:"/DevtZbplanItemEntityController/getAllZbToAdd",
            where:data,
            loading:true,
            page: false,
            parseData:function(res){
                return {
                    code:res.code,
                    msg:res.msg,
                    data: res.data
                }
            }
        });

    }


    function bindForm(){
        dlCommon.getJSON("/DevtZbclassInfoEntityController/getAll",{},function(res){
            var str='<option value="">全部</option>';
            $(res.data).each(function(i,d){
                str+='<option value="'+d.id+'">'+d.zbclassname+'</option>';
            })
            $("#selType").html(str);
            layui.form.render();
        });

    }
    //初始化grid
    function initGrid(){
        //第一个实例
        layui.table.render({
            elem: '#mygrid'
            ,id:'mygrid'
            ,height: 419
            ,height: height-50
            ,size: 'sm' //小尺寸的表格
            ,page: false //开启分页
            ,cols: [
                [ //表头
                    {type: 'checkbox'}
                    ,{field: 'xh', title: '序号', width:'8%'}
                    ,{field: 'zbclassname', title: '分类名称',filter:true, width:'15%'}
                    ,{field: 'zbname', title: '指标名称',filter:true, width:'15%',}
                    ,{field: 'zbcode', title: '指标代码',filter:true, width:'20%'}
                    ,{field: 'zbbz', title: '备注',filter:true, width:'20%',}
                ]],
            filter: {
                bottom: false
            },
            done: function() {
                // 在 done 中开启
                layui.soulTable.render(this)
            }
        });


    }
    //初始化事件
    function initEvent(){
        /*增删改点击方法*/
        $('.btnwrap>button').on('click',function(){
            var names = $(this)[0].name;
            //新增
            if(names == 'add'){
                var checkStatus = layui.table.checkStatus('mygrid'); //idTest 即为基础参数 id 对应的值
                console.log(checkStatus.data) //获取选中行的数据
                if(checkStatus.data.length==0){
                    dlCommon.layerInfo('请选择指标');
                    return;
                }
                var zbidStr="";
                for (let i = 0; i < checkStatus.data.length; i++) {
                    var dataOne = checkStatus.data[i];
                    zbidStr=zbidStr+dataOne.id
                    if(i!=checkStatus.data.length-1){
                        zbidStr=zbidStr+","
                    }
                }
                dlCommon.post("/DevtZbplanItemEntityController/saveSelectZb",{planid:planid,zbidStr:zbidStr},function(res){
                    if(!res.success){
                        dlCommon.layerError(res.msg);
                        return;
                    }
                    dlCommon.layerSuccess("保存成功",function(){
                        closeWin();
                    })

                },true);

                return;
            }
        })
    }

    function closeWin(){
        dlCommon.closeParentLayer();
    }
</script>
</html>
